package com.example.peibei.ui.activity;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.dingtao.common.bean.User;
import com.dingtao.common.core.DataCall;
import com.dingtao.common.core.WDActivity;
import com.dingtao.common.core.exception.ApiException;
import com.dingtao.common.util.SPUtils;
import com.example.peibei.R;
import com.example.peibei.base.SpConstant;
import com.example.peibei.bean.SpUserInfoCall;
import com.example.peibei.service.presenter.UserInfoPresenter;
import com.example.peibei.ui.fragment.MeFragment;
import com.example.peibei.ui.utils.LevelImage;

import butterknife.BindView;
import butterknife.OnClick;

public class AccountSafeActivity extends WDActivity {
    @BindView(R.id.tv_password)
    TextView tv_password;
    @BindView(R.id.tv_pay_pwd)
    TextView tv_pay_pwd;
    @BindView(R.id.tv_phone)
    TextView tv_phone;

    private SPUtils spUtils;
    private String password;
    private String payPwd;
    private UserInfoPresenter userInfoPresenter;
    private String token;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_account_safe;
    }

    @Override
    protected void initView() {
        spUtils = new SPUtils(AccountSafeActivity.this, SpConstant.USER_TOKEN);
        token = spUtils.getString(SpConstant.USER_TOKEN);
        userInfoPresenter = new UserInfoPresenter(new UserInfoCall());
        password = spUtils.getString(SpConstant.PASSWORD);
        payPwd = spUtils.getString(SpConstant.PAY_PWD);
        if (password.equals("false")) {
            tv_password.setText("设置登录密码");
        } else {
            tv_password.setText("登录密码");
        }
        if (payPwd.equals("false")) {
            tv_pay_pwd.setText("设置支付密码");
        } else {
            tv_pay_pwd.setText("支付密码");
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        userInfoPresenter.reqeust("Bearer " + token);
    }

    @OnClick(R.id.iv_back)
    public void back() {
        finish();
    }

    @OnClick(R.id.rl_set_password)
    public void setPassword() {
        intent(SettingLoginPswActivity.class);
    }

    @OnClick(R.id.rl_set_pay_pwd)
    public void setPayPassword() {
        intent(SettingPayPswActivity.class);
    }

    @OnClick(R.id.rl_reset)
    public void reset() {
        intent(CancellationActivity.class);
    }

    @OnClick(R.id.rl_change_number)
    public void changePhone() {
        intent(ChangePhoneActivity.class);
    }

    class UserInfoCall extends SpUserInfoCall {

        @Override
        public void success(User data, Object... args) {
            super.success(data,args);
            if (!TextUtils.isEmpty(data.getMobile())){
                tv_phone.setText(data.getMobile());
            }
        }

        @Override
        public void fail(ApiException e, Object... args) {

        }
    }

    @Override
    protected void destoryData() {

    }
}
